#ifndef CHATCLIENT_H
#define CHATCLIENT_H

#include <QtCore/QObject>
#include <QtWebSockets/QWebSocket>

class ChatClient : public QObject
{
    Q_OBJECT
public:
    enum MsgTypeRole {
        UserListRole = 0,
        BroadcastRole,
        BindRole,
        AudioRole
    };
    explicit ChatClient(const QUrl &url, bool debug = false, QObject *parent = Q_NULLPTR);

signals:
    void closed();
    void textMessageReceived(QString message);

public slots:
    void send(QString message);
    void send(QByteArray data);
private slots:
    void onConnected();
    void onTextMessageReceived(QString message);
    void onSocketError(QAbstractSocket::SocketError err);
private:
    QWebSocket m_webSocket;
    QUrl m_url;
    bool m_debug;
};

#endif // CHATCLIENT_H
